home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2007 December / PCWKCD1207B.iso / Blogowanie poza sfera / Scribefire-1.4.2 / scribefire-1.4.2-fx+fl.xpi / chrome / content / blogXML.js < prev    next >
Encoding:
Text File  |  2007-07-16  |  21.1 KB  |  472 lines

  1. /*
  2. Blog XML Javascript
  3. --------------------------------
  4. A poor attempt to keep all blog XML manipulation code here
  5. */
  6. const bloglistxmlfile = "performancing-bloglist.xml";
  7.  
  8. //For testing only
  9. //var gBlogObject = null;
  10. //var gTempBlogObject = new Object();
  11.  
  12. performancingUtil.prototype.deleteBlogEntry = function(theListObject){
  13.     var blogGroup = document.getElementById("blog-group");
  14.     
  15.     if (blogGroup.selectedItem) {
  16.         var theGUID = blogGroup.selectedItem.getAttribute('blogGUID');
  17.         var writeConfirmed = performancingUtil.prototype.removeBlogEntryFromXML(theGUID);
  18.  
  19.         if(!writeConfirmed){
  20.             var errorMessage = performancingUI.getLocaleString('errordeletingblog', []);
  21.             // Error deleting the selected Blog entry\n Please try again.
  22.             alert(errorMessage);
  23.         }
  24.         else {
  25.             //Reload the file - in the future, only remove the item form the listbox
  26.             performancingUI.init();
  27.         }
  28.     }
  29.     else {
  30.             var alertMessage = performancingUI.getLocaleString('mustselectblog', []);
  31.             alert(alertMessage);
  32.     }
  33. }
  34.  
  35. performancingUtil.prototype.removeBlogEntryFromXML = function(theGUID){
  36.     try{
  37.         var file = gPerformancingUtil.getXMLFile();
  38.         var theXMLString = PerFormancingFileIO.read(file, "UTF-8");
  39.         var theBlogXML = new XML(theXMLString);
  40.         //dump("The Read XML: " + theBlogXML..GUID + '\n' + "GUID to Delete:" + theGUID + '\n')
  41.         //delete dude..blog.(GUID == theGUID);
  42.         var entryIndex = theBlogXML.blogs.blog.(GUID == theGUID ).childIndex();
  43.         delete theBlogXML.blogs.blog[entryIndex];
  44.         //Now save the file
  45.         var newWrite = PerFormancingFileIO.write(file, theBlogXML.toString(), "w", "UTF-8");
  46.         if(!newWrite) {
  47.             var errorMessage = performancingUI.getLocaleString('cannotwritetofile', []);
  48.             //Can not write to file, you may not have the correct permissions
  49.             alert(errorMessage);
  50.             return false;
  51.         }
  52.         try{
  53.             gPerformancingUtil.prefs.setCharPref("settings.lastselected.blog", theBlogXML..blog.GUID[0]);
  54.         }catch(e){
  55.         }
  56.         
  57.         return true;
  58.     }catch(e){
  59.         //dump('Delete Error: ' + e + '\n');
  60.         return false;
  61.     }
  62. }
  63.  
  64.  
  65. performancingUtil.prototype.getArrOfCatChecked = function(checkListIDname, isMT){
  66.     var checkList = document.getElementById(checkListIDname);
  67.     var tempArray = [];
  68.     if(isMT){
  69.         for(i=0; i < checkList.childNodes.length; i++ ){
  70.             try{
  71.                 if(checkList.childNodes[i].checked){
  72.                     //var myResponse = myServiceObject.setPostCategories('123', [{'dude' : 'dude2'}, {'dude3' : 'dude4'} ]);
  73.                     var tempStruct = {'categoryId' : checkList.childNodes[i].getAttribute('cat') };
  74.                     //dump("\n CategoryId: " + checkList.childNodes[i].getAttribute('cat') + "\n" )
  75.                     tempArray.push(tempStruct);
  76.                     //dump("\n tempArray: " + tempArray + "\n");
  77.                 }
  78.             }catch(e){
  79.                 //foo
  80.             }
  81.         }
  82.     }else{
  83.         for(i=0; i < checkList.childNodes.length; i++ ){
  84.             try{
  85.                 if(checkList.childNodes[i].checked){
  86.                     //var myResponse = myServiceObject.setPostCategories('123', [{'dude' : 'dude2'}, {'dude3' : 'dude4'} ]);
  87.                     var tempString = checkList.childNodes[i].label;
  88.                     //dump("\n CategoryId: " + checkList.childNodes[i].getAttribute('cat') + "\n" )
  89.                     tempArray.push(tempString);
  90.                     //dump("\n tempArray: " + tempArray + "\n");
  91.                 }
  92.             }catch(e){
  93.                 //foo
  94.             }
  95.         }
  96.     }
  97.     //alert("tempStruct.categoryId: " + tempStruct.categoryId);
  98.     return tempArray;
  99. }
  100.  
  101.  
  102. // #### API GETTERS #### 
  103.  
  104. performancingUtil.prototype.getCategoryList = function(theGUID){
  105.     //dump("Get Category List if you can\n");
  106.     var theBlogXML = gPerformancingUtil.serviceObjectXML;
  107.     //
  108.     var myServiceObject = gPerformancingUtil.serviceObject;
  109.     var myResponse = myServiceObject.getCategoryList();
  110.     var localeString2 = performancingUI.getLocaleString('notavailable', []);
  111.     if(myResponse){
  112.         //dump("Get Cetegory Response ###########:\n" + myResponse + "\n");
  113.         gPerformancingUtil.clearCheckListOut('blog-sidebar-listing-categories');
  114.         var localeString = performancingUI.getLocaleString('fetchingcategories', []);
  115.         //Fetching Categories..
  116.         gPerformancingUtil.addItemToCheckList([localeString], 0, 'blog-sidebar-listing-categories', null, localeString2, "", 'label' );
  117.         performancing_xmlcall.sendCommand(theBlogXML.apiurl.toString(), myResponse, 'categorycall', "", "", performancing_xmlcall.processData);
  118.     }else{
  119.         //Disable the category section
  120.         //dump("Category Response Error: ###########:\n" + myResponse + "\n");
  121.         gPerformancingUtil.clearCheckListOut('blog-sidebar-listing-categories');
  122.         var localeString = performancingUI.getLocaleString('nocategoriesavailable', []);
  123.         //No Categories Available
  124.         gPerformancingUtil.addItemToCheckList([localeString], 0, 'blog-sidebar-listing-categories', null, localeString2, "", 'label' );
  125.     }
  126. }
  127.  
  128. performancingUtil.prototype.getBlogPages = function (theGUID) {
  129.     var theBlogXML = gPerformancingUtil.serviceObjectXML;
  130.     var myServiceObject = gPerformancingUtil.serviceObject;
  131.  
  132.     // Set number of history pages to get.
  133.     var numOfPosts = 10; 
  134.     
  135.     try { numOfPosts = gPerformancingUtil.prefs.getIntPref("display.history.numbertoshow"); } catch(e) { numOfPosts = 10; }
  136.  
  137.     var myResponse = myServiceObject.getPages();
  138.     performancing_xmlcall.sendCommand(theBlogXML.apiurl.toString(), myResponse, 'pagescall', null, theGUID, performancing_xmlcall.processData);
  139.     
  140.     var localeString = performancingUI.getLocaleString('notavailable', []);
  141.     
  142.     if (theBlogXML..blogtype == "wordpress_cust") {
  143.         gPerformancingUtil.clearListOut('performancing-pages-list');
  144.         
  145.         if (myResponse) {
  146.             var localeString2 = performancingUI.getLocaleString('loading', []);
  147.             gPerformancingUtil.addItemToList([localeString2], 0, 'performancing-pages-list', null, localeString, "");
  148.         } else {
  149.             gPerformancingUtil.addItemToList([localeString], 0, 'performancing-pages-list', null, localeString, "");
  150.         }
  151.     }
  152.     else {
  153.         gPerformancingUtil.clearListOut('performancing-pages-list');
  154.         gPerformancingUtil.addItemToList([localeString], 0, 'performancing-pages-list', null, localeString, "");
  155.     }
  156. };
  157.  
  158. performancingUtil.prototype.getBlogHistory = function(theGUID){
  159.     //dump("Get Blog history if you can\n");
  160.     var theBlogXML = gPerformancingUtil.serviceObjectXML;
  161.     var myServiceObject = gPerformancingUtil.serviceObject;
  162.     
  163.     //Set number of history posts to get.
  164.     var numOfPosts = 10; 
  165.     try{
  166.         numOfPosts = gPerformancingUtil.prefs.getIntPref("display.history.numbertoshow");
  167.     }catch(e){
  168.         numOfPosts = 10;
  169.     }
  170.     
  171.     var myResponse = myServiceObject.getRecentPosts(numOfPosts);
  172.     //first 3 are for legacy support (v1.0)
  173.     if( !(theBlogXML..blogtype == "blogger_com") || !(theBlogXML..blogtype == "livejournal_atom_com") || !(theBlogXML..blogtype == "atom_cust") || !(theBlogXML..blogtype == "s_atom")    || !(theBlogXML..blogtype == "atom") || !(theBlogXML..blogtype == "atom_blogger")   ){
  174.         var localeString = performancingUI.getLocaleString('notavailable', []);
  175.         if(myResponse){
  176.             //dump("Get History Response ###########:\n" + myResponse + "\n");
  177.             var localeString2 = performancingUI.getLocaleString('loading', []);
  178.             gPerformancingUtil.clearListOut('performancing-history-list');
  179.             gPerformancingUtil.addItemToList([localeString2], 0, 'performancing-history-list', null, localeString, "" );
  180.             performancing_xmlcall.sendCommand(theBlogXML.apiurl.toString(), myResponse, 'historycall', null, theGUID, performancing_xmlcall.processData);
  181.         }else{
  182.             //dump("History Response Error ###########:\n" + myResponse + "\n");
  183.             gPerformancingUtil.clearListOut('performancing-history-list');
  184.             //dataArray, number, listIDname, theGUID, theURL, onItemClick, aDate, aPostId
  185.             gPerformancingUtil.addItemToList([localeString], 0, 'performancing-history-list', null, localeString, "" );
  186.         }
  187.     }else{
  188.         
  189.     }
  190. }
  191.  
  192. // #### API SETTERS
  193.  
  194. //gPerformancingUtil.prefs.getCharPref("settings.lastselected.blog");
  195. performancingUtil.prototype.postCurrentItem = function(){
  196.     //dump("Post Current Item if you can\n");
  197.     var theGUID = gPerformancingUtil.prefs.getCharPref("settings.lastselected.blog");
  198.     if(gSelectedBlog != null && gSelectedBlog != 'null'){
  199.         var theBlogXML = gPerformancingUtil.serviceObjectXML;
  200.         
  201.         var myServiceObject = gPerformancingUtil.serviceObject;
  202.         //figure out which HTML to grab (source or rich)
  203.         var tabbox = document.getElementById("performancing-editor-tabbox");
  204.         
  205.         //Insert Technorati tags automatically?
  206.         //performancingUI.insertTechnorati()
  207.         if( gPerformancingUtil.prefs.getBoolPref('extra.inserttechnorati') ){
  208.             performancingUI.insertTechnorati();
  209.         }
  210.         //Insert Powered by Performancing
  211.         if( gPerformancingUtil.prefs.getBoolPref('extra.insertpfftext2')){
  212.             performancingUI.insertPoweredByPFF();
  213.         }
  214.         
  215.         var theContent = null;
  216.         //dump('Content Tab Selected: ' + tabbox.selectedIndex + '\n');
  217.         if(tabbox.selectedIndex == 0 || tabbox.selectedIndex == 2){//Rich or preview
  218.             var winNormal = document.getElementById("performancing-message");
  219.             theContent = winNormal.contentWindow.document.body.innerHTML;
  220.         }else if(tabbox.selectedIndex == 1){ //Source
  221.             //If pref, convert chartype
  222.             //gPerformancingUtil.convertFromUnicode
  223.             theContent = document.getElementById("performancing-message-source").value
  224.         }else{
  225.             var localeString = performancingUI.getLocaleString('couldnotfindcontent', []);
  226.             //PerFormancing Error: Could not find content, please contact the author
  227.             alert(localeString);
  228.         }
  229.         if(theContent != null){
  230.             if( performancingUI.checkSubjectEmpty() ){
  231.                 var theTitle = document.getElementById("performancing-editor-subject").value;
  232.                 //If LiveJournal, add Title
  233.                 theContent = performancingMidas.getXHTML(theContent);
  234.                 
  235.                 if(theBlogXML.blogtype == 'livejournal_com'){
  236.                     theContent = theContent + "<title>" + theTitle + "</title>";
  237.                 }
  238.                 
  239.                 //Send as specified by encoding pref
  240.                 var theBlogCharType = gPerformancingUtil.getCharType();
  241.                 //theContent = gPerformancingUtil.convertFromUnicode(theContent, theBlogCharType);
  242.                 
  243.                 var publishThisPost = 1;
  244.                 var isDraft = document.getElementById("performancing-draft-checkbox").checked;
  245.                 //var useBool =     gPerformancingUtil.prefs.getBoolPref("publishing.truebool");
  246.                 var useBool =  gPerformancingUtil.useBooleanPublish(theBlogXML.blogtype, theBlogXML.useboolean);
  247.                 
  248.                 if(isDraft){
  249.                     publishThisPost = 'bool0';
  250.                     if(useBool){
  251.                         publishThisPost = false;
  252.                     }
  253.                 }else{
  254.                     publishThisPost = 'bool1';
  255.                     if(useBool){
  256.                         publishThisPost = true;
  257.                     }
  258.                 }
  259.                 
  260.                 // If the pages tab is selected, post this as a page.
  261.                 if (document.getElementById('performancing-sidebar-vbox').getAttribute("selectedIndex") == "4") {
  262.                     var myResponse = myServiceObject.newPage(theTitle, theContent, null, publishThisPost);
  263.                     
  264.                     performancingUI.toggleEnableOnPost();
  265.                     performancingUI.onServerSend();
  266.                     performancing_xmlcall.sendCommand(theBlogXML.apiurl.toString(), myResponse, 'newpagecall', null, "", performancing_xmlcall.processData);
  267.                 }
  268.                 else {
  269.                     var catArray1 = this.getArrOfCatChecked('blog-sidebar-listing-categories', false);
  270.                     var myResponse = myServiceObject.newPost(theTitle, theContent, catArray1, null, publishThisPost);//Should it be 1?
  271.                     
  272.                     performancingUI.toggleEnableOnPost();
  273.                     performancingUI.onServerSend();
  274.                     var catArray = this.getArrOfCatChecked('blog-sidebar-listing-categories', true);
  275.                     performancing_xmlcall.sendCommand(theBlogXML.apiurl.toString(), myResponse, 'newpostcall', catArray, "", performancing_xmlcall.processData);
  276.                 }
  277.             }else{
  278.                 //dump('Subjet was empty, canceled \n');
  279.             }
  280.         }
  281.     }else{
  282.         var localeString = performancingUI.getLocaleString('pleaseselectablogs', []);
  283.         alert(localeString);
  284.     }
  285. }
  286.  
  287. performancingUtil.prototype.useBooleanPublish = function(aBlogType, usesBoolean){
  288.     //alert(" theBlogXML.blogtype: " + aBlogType + " usesBoolean: " + usesBoolean.toString() );
  289.     if(usesBoolean.toString() == 'true'){
  290.         return true;
  291.     }else{
  292.         switch (aBlogType.toString()) { //this._fareWatcherState = FAREWATCHER_STATE_ERROR;
  293.                 case 'drupal_cust':
  294.                 case 'performancing_com':
  295.                     return true;
  296.                     break;
  297.                     
  298.                 default:
  299.                     return false;
  300.                     break;
  301.         }
  302.     }
  303.     return false;
  304. }
  305.  
  306. //TODO, mush this and postCurrentItem together with a flag
  307. performancingUtil.prototype.editCurrentItem = function(){
  308.     //dump("Post Current Item if you can\n");
  309.     var theGUID = gPerformancingUtil.prefs.getCharPref("settings.lastselected.blog");
  310.     var pubButton = document.getElementById("performancing-republish-button");
  311.     var thePostID = pubButton.getAttribute("lastpostid");
  312.     var theDateCreated = pubButton.getAttribute("datecreated");
  313.     if(gSelectedBlog != null && gSelectedBlog != 'null'){
  314.         var theBlogXML = gPerformancingUtil.serviceObjectXML;
  315.         var theBlogType = theBlogXML.blogtype.toString();
  316.         
  317.         //Hard coded, if it's wordpress, leave dateCreated blank
  318.         if(theBlogType == "wordpress_com" || theBlogType == "wordpress_cust" ){
  319.             theDateCreated = "";
  320.         }
  321.         
  322.         var myServiceObject = gPerformancingUtil.serviceObject;
  323.         //figure out which HTML to grab (source or rich)
  324.         var tabbox = document.getElementById("performancing-editor-tabbox");
  325.         var theContent = null;
  326.         //dump('Content Tab Selected: ' + tabbox.selectedIndex + '\n');
  327.         if(tabbox.selectedIndex == 0 || tabbox.selectedIndex == 2){//Rich or preview
  328.             var winNormal = document.getElementById("performancing-message");
  329.             theContent = winNormal.contentWindow.document.body.innerHTML;
  330.         }else if(tabbox.selectedIndex == 1){ //Source
  331.             theContent = document.getElementById("performancing-message-source").value
  332.         }else{
  333.             var localeString = performancingUI.getLocaleString('couldnotfindcontent', []);
  334.             //PerFormancing Error: Could not find content, please contact the author
  335.             alert(localeString);
  336.         }
  337.         if(theContent != null){
  338.             if( performancingUI.checkSubjectEmpty() ){
  339.                 var theTitle = document.getElementById("performancing-editor-subject").value;
  340.                 //If LiveJournal, add Title
  341.                 theContent = performancingMidas.getXHTML(theContent);
  342.                 
  343.                 if(theBlogXML.blogtype == 'livejournal_com'){
  344.                     theContent = theContent + "<title>" + theTitle + "</title>";
  345.                 }
  346.                 
  347.                 //Send as specified by encoding pref
  348.                 var theBlogCharType = gPerformancingUtil.getCharType();
  349.                 //theContent = gPerformancingUtil.convertFromUnicode(theContent, theBlogCharType);
  350.                 
  351.                 var publishThisPost = 1;
  352.                 var isDraft = document.getElementById("performancing-draft-checkbox").checked;
  353.                 var useBool =  gPerformancingUtil.useBooleanPublish(theBlogXML.blogtype, theBlogXML.useboolean);
  354.                 
  355.                 if(isDraft){
  356.                     publishThisPost = 'bool0';
  357.                     if(useBool){
  358.                         publishThisPost = false;
  359.                     }
  360.                 }else{
  361.                     publishThisPost = 'bool1';
  362.                     if(useBool){
  363.                         publishThisPost = true;
  364.                     }
  365.                 }
  366.                 var catArray1 = this.getArrOfCatChecked('blog-sidebar-listing-categories', false);
  367.                 var myResponse = myServiceObject.editPost(thePostID, theTitle, theContent, catArray1, theDateCreated, publishThisPost);
  368.                 //dump("Get New Post Response ###########:\n" + myResponse + "\n");
  369.                 performancingUI.toggleEnableOnPost();
  370.                 performancingUI.onServerSend();
  371.                 var catArray = this.getArrOfCatChecked('blog-sidebar-listing-categories', true);
  372.                 performancing_xmlcall.sendCommand(theBlogXML.apiurl.toString(), myResponse, 'editpostcall', catArray, "", performancing_xmlcall.processData);
  373.                 
  374.             }else{
  375.                 //dump('Subjet was empty, canceled \n');
  376.             }
  377.         }
  378.     }else{
  379.         var localeString = performancingUI.getLocaleString('pleaseselectablogs', []);
  380.         //Please Select a Blog before trying to publish!
  381.         alert(localeString);
  382.     }
  383. }
  384.  
  385. performancingUtil.prototype.setCategoryList = function(aPostID, catArray){
  386.     //dump("Get Category List if you can\n");
  387.     var theGUID = gPerformancingUtil.prefs.getCharPref("settings.lastselected.blog");
  388.     var theBlogXML = gPerformancingUtil.serviceObjectXML;
  389.     
  390.     var myServiceObject = gPerformancingUtil.serviceObject;
  391.     var myResponse = myServiceObject.setPostCategories(aPostID, catArray);
  392.     //publishPost
  393.     
  394.     if(myResponse){
  395.         //dump("Get Category  SET Response ###########:\n" + myResponse + "\n");
  396.         performancing_xmlcall.sendCommand(theBlogXML.apiurl.toString(), myResponse, 'setcategoriescall', null, null, performancing_xmlcall.processData );
  397.     }else{
  398.         //Disable the cetagory section
  399.         //dump("Category SET Response Error: ###########:\n" + myResponse + "\n");
  400.     }
  401.     //Now publish it! This fixes a typepad category bug
  402.     //gPerformancingUtil.publishThePost(gLastPostID);
  403. }
  404.  
  405. performancingUtil.prototype.publishThePost = function(aPostID){
  406.     //dump("Publish Post\n");
  407.     var theGUID = gPerformancingUtil.prefs.getCharPref("settings.lastselected.blog");
  408.     var theBlogXML = gPerformancingUtil.serviceObjectXML;
  409.     
  410.     var myServiceObject = gPerformancingUtil.serviceObject;
  411.     var myResponse = myServiceObject.publishPost(aPostID);
  412.     //publishPost
  413.     
  414.     if(myResponse){
  415.         //dump("Publish POST Response ###########:\n" + myResponse + "\n");
  416.         performancing_xmlcall.sendCommand(theBlogXML.apiurl.toString(), myResponse, 'publishPost', null, null, performancing_xmlcall.processData );
  417.     }else{
  418.         //Disable the cetagory section
  419.         //dump("Published Post Response Error: ###########:\n" + myResponse + "\n");
  420.     }
  421. }
  422.  
  423. performancingUtil.prototype.deleteHistoryItem = function(){
  424.     var confirmText = performancingUI.getLocaleString("deletepostconfirm", []);
  425.     if (confirm(confirmText)){
  426.     //dump("Delete Item if you can\n");
  427.     var theGUID = gPerformancingUtil.prefs.getCharPref("settings.lastselected.blog");
  428.     var theBlogXML = gPerformancingUtil.serviceObjectXML;
  429.     var theListElement = document.getElementById('performancing-history-list');
  430.     var thePostID = theListElement.selectedItem.getAttribute('postid');
  431.     
  432.     try{
  433.         var myServiceObject = gPerformancingUtil.serviceObject;
  434.         var myResponse = myServiceObject.deletePost(thePostID);
  435.         if(myResponse){
  436.             performancing_xmlcall.sendCommand(theBlogXML.apiurl.toString(), myResponse, 'deletehistorycall', null, null, performancing_xmlcall.processData);
  437.             performancingMidas.makeBlank(); //clear out the onte area.
  438.             performancingUI.toggleExtraOptDeck(true);
  439.             //performancingUI.clearTechnoratiTags();
  440.         }else{
  441.             //foo
  442.         }
  443.     }catch(e){
  444.         var localeString = performancingUI.getLocaleString('selectitemtodelete', [e]);
  445.         alert(localeString);
  446.     }
  447.     }
  448. }
  449.  
  450. performancingUtil.prototype.deletePage = function(){
  451.     if (confirm("Are you sure? This will permanently delete the selected page from your blog.")) {
  452.     var theGUID = gPerformancingUtil.prefs.getCharPref("settings.lastselected.blog");
  453.     var theBlogXML = gPerformancingUtil.serviceObjectXML;
  454.     var theListElement = document.getElementById('performancing-pages-list');
  455.     var thePostID = theListElement.selectedItem.getAttribute('postid');
  456.     
  457.     try{
  458.         var myServiceObject = gPerformancingUtil.serviceObject;
  459.         var myResponse = myServiceObject.deletePage(thePostID);
  460.         
  461.         if(myResponse){
  462.             performancing_xmlcall.sendCommand(theBlogXML.apiurl.toString(), myResponse, 'deletepagecall', null, null, performancing_xmlcall.processData);
  463.             performancingMidas.makeBlank();
  464.             performancingUI.toggleExtraOptDeck(true);
  465.         }
  466.     }catch(e){
  467.         var localeString = performancingUI.getLocaleString('selectitemtodelete', [e]);
  468.         alert(localeString);
  469.     }
  470.     }
  471. }
  472.